﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace DataMining
{
    /// <summary>
    /// 属性的表示：mValues，属性的取值范围；mName，属性的名称；mClass，最终的分类
    /// </summary>
    public class Attribute
    {
        ArrayList mValues;
        string mName;
        object mClass;

        /// <summary>
        /// 此类的构造函数，mClass为空
        /// </summary>
        /// <param name="name">属性的名称</param>
        /// <param name="values">属性的取值范围</param>
        public Attribute(string name, string[] values)
        {
            mName = name;
            mValues = new ArrayList(values);
            mValues.Sort();
        }

        public Attribute(object Label)
        {
            mClass = Label;
            mName = string.Empty;
            mValues = null;
        }

        /// <summary>
        /// 返回此属性的名称
        /// </summary>
        public string AttributeName
        {
            get
            {
                return mName;
            }
        }

        /// <summary>
        /// 返回此属性的所有取值
        /// </summary>
        public string[] values
        {
            get
            {
                if (mValues != null)
                    return (string[])mValues.ToArray(typeof(string));
                else
                    return null;
            }
        }

        /// <summary>
        /// 判断某属性值是否属于此属性
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool isValidValue(string value)
        {
            return indexValue(value) >= 0;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public int indexValue(string value)
        {
            if (mValues != null)
                return mValues.BinarySearch(value);
            else
                return -1;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            if (mName != string.Empty)
            {
                return mName;
            }
            else
            {
                return mClass.ToString();
            }
        }
    }
}
